/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 combat_reader.h

	$Header: /heroes4/combat_reader.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( COMBAT_READER_H_INCLUDED )
#define COMBAT_READER_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <iosfwd>
#include <map>
#include <vector>
#include "compound_object_ptr.h"

class t_abstract_combat_object;
class t_attackable_obstacle;
class t_battlefield;
class t_castle_gate;
class t_combat_creature;
class t_combat_label;
class t_combat_saveable_object;
class t_object_segment;
class t_stationary_combat_object;

typedef t_counted_ptr< t_combat_saveable_object > t_combat_saveable_object_ptr;
typedef t_counted_const_ptr< t_combat_saveable_object > t_combat_saveable_object_const_ptr;

// ----------------------------------------------------------------------
// helper class for reading combat maps.  Contains temporary data
// that is not required after reading finishes.
// ----------------------------------------------------------------------
class t_combat_reader
{
public:
	t_combat_reader( t_battlefield& battlefield, std::streambuf& stream );

	t_battlefield&				get_battlefield();
	std::streambuf&				get_stream();
	t_abstract_combat_object*	read_abstract_object();
	t_attackable_obstacle*		read_attackable_obstacle();
	t_compound_object*			read_compound_object();
	t_combat_creature*			read_creature();
	t_combat_label*				read_label();
	t_castle_gate*				read_gate();
	t_object_segment*			read_segment();
	t_stationary_combat_object*	read_stationary_object();
private:
	typedef std::vector<t_combat_saveable_object_ptr> t_object_array;

	t_combat_saveable_object* read_object();

	t_battlefield&	m_battlefield;
	t_object_array	m_objects;
	std::streambuf&	m_stream;
};

inline 	t_combat_reader::t_combat_reader( t_battlefield&	battlefield, 
													std::streambuf& stream )
							: m_battlefield( battlefield ), m_stream( stream )
{
}

inline t_battlefield& t_combat_reader::get_battlefield()
{
	return m_battlefield;
}

inline std::streambuf& t_combat_reader::get_stream() 
{
	return m_stream;
}

// ----------------------------------------------------------------------
// helper class for writing combat maps.  Contains temporary data
// that is not required after writing finishes.
// ----------------------------------------------------------------------
class t_combat_writer
{
public:
	t_combat_writer( t_battlefield const& battlefield, std::streambuf& stream );

	t_battlefield const&	get_battlefield();
	std::streambuf&			get_stream();
	bool					write( t_combat_saveable_object const* object );
private:
	typedef std::map< t_combat_saveable_object_const_ptr, int > t_object_indexed_array;

	t_battlefield const&	m_battlefield;
	t_object_indexed_array	m_objects;
	std::streambuf&			m_stream;
};

inline 	t_combat_writer::t_combat_writer( t_battlefield const& battlefield, 
													std::streambuf& stream )
							: m_battlefield( battlefield ), m_stream( stream )
{
}

inline t_battlefield const& t_combat_writer::get_battlefield()
{
	return m_battlefield;
}

inline std::streambuf& t_combat_writer::get_stream() 
{
	return m_stream;
}


#endif